
import store from "@/store";
import Cache from '@/utils/cache';

import cfg from '@/config/app';

export function checkLogin() {
	let token = Cache.get(cfg.LOGIN_STATUS);
	
	let expiresTime = Cache.get(cfg.EXPIRES_TIME);
	let newTime = Math.round(new Date() / 1000);
	
	if ( !token) {
		uni.setStorageSync('authIng', false)
		Cache.clear(cfg.LOGIN_STATUS);
		Cache.clear(cfg.EXPIRES_TIME);
		Cache.clear(cfg.USER_INFO);
		Cache.clear(cfg.STATE_R_KEY);
		return false;
	} else {
		store.commit('UPDATE_LOGIN', token);
		return true;
	}

}
export function logout(){
	Cache.clear(cfg.LOGIN_STATUS);
	Cache.clear(cfg.EXPIRES_TIME);
	Cache.clear(cfg.USER_INFO);
	Cache.clear(cfg.UID);
	Cache.clear('step');
	Cache.clear('mobile');
}
export function toLogin(){
	uni.login({
	  provider: 'weixin', //使用微信登录
	  success: function (loginRes) {
		console.log(loginRes);
		uni.getUserProfile({
		      provider: 'weixin',
		      success: function (infoRes) {
		        console.log('用户昵称为：' + infoRes.userInfo.nickName);
		      },
			  fail(e) {
			  	console.log(e);
			  }
		    });
	  }
	});
}




